﻿using System;
using System.Threading.Tasks;

namespace WebMiddleware
{
    internal class ApplicationTaskProxy : ITaskProxy
    {
        private readonly WpfApplication _app;

        public ApplicationTaskProxy(WpfApplication app)
        {
            _app = app;
        }

        public async Task Invoke(Action action)
        {
            await Task.Run(() =>
            {
               _app.Dispatcher.Invoke(action);
            });
        }

        public async Task<TResult> InvokeAsync<TResult>(Func<TResult> func)
        {
            return await Task.Run(() =>
            {
                return _app.Dispatcher.Invoke(func);
            });
        }
    }
}
